<%@ page import="java.util.Hashtable,
                 ro.gateway.aida.srv.EditorServlet,
                 ro.gateway.aida.usr.EditUserServlet,
                 ro.gateway.aida.srv.ICFService,
                 ro.gateway.aida.servlet.Constants,
                 ro.gateway.aida.fnd.*,
                 ro.gateway.aida.obj.Currency,
                 ro.gateway.aida.obj.db.CurrencyDB,
                 ro.gateway.aida.utils.HttpUtils,
                 ro.gateway.aida.db.PersistenceToken,
                 ro.gateway.aida.db.PersistenceManager,
			  ro.gateway.aida.admin.PropertyList,
			  ro.gateway.aida.admin.PropertyListDB,
			  java.util.ArrayList,
			  ro.gateway.aida.obj.Organization,
			  ro.gateway.aida.obj.db.OrganizationDB"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="gtw" %>
<trans:initPage module="fundings" />
<html>
<%
     Hashtable bean = (Hashtable) request.getAttribute(EditorServlet.PNAME_BEAN);
     if (bean == null) {
          response.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
     }

     String key = (String) bean.get(EditorServlet.PNAME_KEY);
     String ctx = request.getContextPath();
     // edit/delete/new
     FundingYearlyItem item = (FundingYearlyItem) bean.get(EditorServlet.PNAME_BEAN);
     if (item == null)
     return;

     ICFService cfService = (ICFService) ((Hashtable) application.
          getAttribute( Constants.SERVICES )).get( Constants.SERVICE_CF );
      PersistenceToken pers_token = PersistenceManager.
            tokenLookup(application);
      PersistenceToken token = PersistenceManager.tokenLookup( application );
     FundingType[] types = FundingTypePersMan.getManager(pers_token).getAll();
     if (types == null) types = new FundingType[0];
     PropertyList lstatuses = PropertyListDB.getManager(pers_token).getList("fndstatus");
	ArrayList statuses = null;
	if (lstatuses != null) {
		statuses = lstatuses.getItems();
	} else {
		statuses = new ArrayList();
	}
     Currency[] currencies = CurrencyDB.getManager(pers_token).getAll();
     if (currencies == null) currencies = new Currency[0];

     Object screen = request.getAttribute(EditUserServlet.PNAME_SCREEN);
%>
<head>
     <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
     <META HTTP-EQUIV="EXPIRES" CONTENT="0">
     <title><trans:showPageMessage label="title" /></title>
     <link rel="stylesheet" href="../alf.css" type="text/css">
</head>
<body>
<br>
<br>
<table align="center" width="90%" border="0" cellspacing="1" cellpadding="5" background=<%=ctx%>/images/pixelbgtable.gif>
    <form method="POST" action="<%=ctx%>/fnd/efndyearly" name="theform">
    <input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />
    <input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />
<% if (EditUserServlet.PV_SCR_EDIT.equals(screen)) { %>
    <script language="javascript">
        function submit_theform(action) {
            if (document.theform.sbutton) {
                document.theform.sbutton.disabled=1;
            }
            if (document.theform.cbutton) {
                document.theform.cbutton.disabled=1;
            }
            if (document.theform.action) {
                document.theform.action.value=action;
            }

            document.theform.submit();
        }
    </script>
    <tr bgcolor="#FFFFFF">
      <td colspan="2">
      <trans:showPageMessage label="form.yearlytitle" />
      </td>
    </tr>
    <% if (HttpUtils.getValidTrimedString(request, "err", null) != null) { %>
    <tr bgcolor="#FFFFFF">
      <td colspan="2" class="text_search" bgcolor="#FFAAAA">
      <trans:showPageMessage label="form.incorrectdata" />
      </td>
    </tr>
    <% } %>
    <tr bgcolor="#FFFFFF">
      <td align="right" width="30%" class="text_search"><trans:showPageMessage label="form.startdate" /> :</td>
      <td width="70%" class="text_search">
      <gtw:dateSelector aname="asdate" lname="lsdate" zname="zsdate" current_value='<%=item.getStart_date()%>' />
      </td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td align="right" width="30%" class="text_search"><trans:showPageMessage label="form.amount" /> :</td>
      <td width="70%" class="text_search">
        <input type="text" size="20" name="amount" value="<%=item.getAmount()%>" /><br>
        <select name="currency">
        <option value=""><trans:showPageMessage label="form.selcurrency" /></option>
        <% for (int i = 0; i < currencies.length; i++) { %>
            <option <%=(currencies[i].getIso3().equals(item.getCurrency())) ? "selected=\"true\" " : ""%>value="<%=currencies[i].getIso3()%>"><%=currencies[i].getIso3()%> - <%=currencies[i].getName()%></option>
        <% } %>
        </select>
      </td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="2">
        <input name="sbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bsave" />"
        onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CONFIRM%>');">
        <input name="cbutton" type="button" class="butonsave" value="<trans:showPageMessage label="form.bcancel" />"
        onclick="javascript:submit_theform('<%=EditorServlet.PV_ACTION_CANCEL%>');">
      </td>
    </tr>
<% } else if (FundingYearlyEditorServlet.PV_SCREEN_CANCEL.equals(screen)) { %>
    <script language="javascript">
        opener.after_edit_ysubitem(1);
    </script>
<% } else if (FundingYearlyEditorServlet.PV_SCREEN_SAVED.equals(screen)) { %>
    <script language="javascript">
        opener.after_edit_ysubitem(0);
    </script>
<% } else { %>
no screen defined: <%=screen%>
<% } %>
    </form>
</table>
<br><br>
</body>
</html>
